package org.odata4j.examples.producer.jpa.contacts;

import java.io.Serializable;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;


/**
 * Contacts test JPA entity to model how to use @Embeddeable annotated classes
 * in both @EmbeddedId and @Embedded ways.
 * <br/>
 * The @Embedded class in this example is the {@link Address} class, which itself
 * has an @Embedded attribute, {@link AuditLog}.
 * <br/>
 * The {@link Address} @Embeddable class is used twice in this {@link Contacts} class,
 * once as a {@link #HomeAddress} attribute and once as a {@link #WorkAddress} attribute.
 */
@Entity
@Table(name = "Contacts")
public class Contacts implements Serializable {

  private static final long serialVersionUID = 1L;
  
  @EmbeddedId
  private ContactsPK ContactsPK;
  
  @Column(name = "ContactName")
  private String ContactName;
  
  @Column(name = "ContactNumber")
  private Integer ContactNumber;
  
  @Column(name = "ContactAge")
  private Integer ContactAge;
  
  @Embedded
  @AttributeOverrides({
    @AttributeOverride(column = @Column(name="HomeAddress_Address"), name = "Address"),
    @AttributeOverride(column = @Column(name="HomeAddress_City"), name = "City"),
    @AttributeOverride(column = @Column(name="HomeAddress_Region"), name = "Region"),
    @AttributeOverride(column = @Column(name="HomeAddress_PostalCode"), name = "PostalCode"),
    @AttributeOverride(column = @Column(name="HomeAddress_Country"), name = "Country"),
    @AttributeOverride(column = @Column(name="HA_AL_Id"), name = "AuditLog.id"),
    @AttributeOverride(column = @Column(name="HA_AL_Desc"), name = "AuditLog.desc"),
    @AttributeOverride(column = @Column(name="HA_AL_CreatedTime"), name = "AuditLog.createdTime"),
    @AttributeOverride(column = @Column(name="HA_AL_LastModified"), name = "AuditLog.lastModified")
    })
  private Address HomeAddress;
  
  @Embedded
  @AttributeOverrides({
    @AttributeOverride(column = @Column(name="WorkAddress_Address"), name = "Address"),
    @AttributeOverride(column = @Column(name="WorkAddress_City"), name = "City"),
    @AttributeOverride(column = @Column(name="WorkAddress_Region"), name = "Region"),
    @AttributeOverride(column = @Column(name="WorkAddress_PostalCode"), name = "PostalCode"),
    @AttributeOverride(column = @Column(name="WorkAddress_Country"), name = "Country"),
    @AttributeOverride(column = @Column(name="WA_AL_Id"), name = "AuditLog.id"),
    @AttributeOverride(column = @Column(name="WA_AL_Desc"), name = "AuditLog.desc"),
    @AttributeOverride(column = @Column(name="WA_AL_CreatedTime"), name = "AuditLog.createdTime"),
    @AttributeOverride(column = @Column(name="WA_AL_LastModified"), name = "AuditLog.lastModified")
    })
  private Address WorkAddress;

  public Contacts() {}

  public Contacts(ContactsPK contactPK) {
    this.ContactsPK = contactPK;
  }

  public ContactsPK getContactsPK() {
    return ContactsPK;
  }

  public void setContactsPK(ContactsPK contactsPK) {
    this.ContactsPK = contactsPK;
  }

  public String getContactName() {
    return ContactName;
  }

  public void setContactName(String contactName) {
    this.ContactName = contactName;
  }

  public Integer getContactNumber() {
    return ContactNumber;
  }

  public void setContactNumber(Integer contactNumber) {
    this.ContactNumber = contactNumber;
  }

  public Integer getContactAge() {
    return ContactAge;
  }

  public void setContactAge(Integer contactAge) {
    this.ContactAge = contactAge;
  }
  
  /* This is the new composite version:
  */
  public Address getHomeAdddress() {
    return HomeAddress;
  }
  
  public void setHomeAdddress(Address homeAddress) {
    HomeAddress = homeAddress;
  }
  
  public Address getWorkAdddress() {
    return WorkAddress;
  }
  
  public void setWorkAdddress(Address workAddress) {
    WorkAddress = workAddress;
  }
  
  @Override
  public int hashCode() {
    int hash = 0;
    hash += (ContactsPK != null
        ? ContactsPK.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    if (!(object instanceof Contacts)) {
      return false;
    }
    Contacts other = (Contacts) object;
    if ((this.ContactsPK == null && other.ContactsPK != null)
        || (this.ContactsPK != null && !this.ContactsPK
            .equals(other.ContactsPK))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "org.odata4j.examples.producer.jpa.northwind.Contacts[contactsPK="
        + ContactsPK + ", ContactName=" + ContactName + ", ContactNumber=" + ContactNumber + ", ContactAge=" + ContactAge + ", HomeAddress=" + HomeAddress  + ", WorkAddress=" + WorkAddress + "]";
  }
}
